<?php        
    class UserWeightModel extends Model {        
        public static $classDesc = "User weight";
        
        public static $keyDesc = array(
            "id"                => "ID",
            "hashid"            => "Hashid",
            "userid"            => "User ID",
            "weight_kg"         => "Weight (KG)",
            "weight_lb"         => "Weight (LB)",
            "unit"              => "Unit",
            "measurement_time"  => "Measurement time",
            "fatpercent"        => "Fat percent",
            "date"              => "Date",
            "rowstamp"          => "Created"
        );
        
        public function __construct($id = null) {
            $this->_table = "user_weight";
            
            parent::__construct($id);
            
            # Yksiköiden minimit
            parent::$_schema["user_weight"]["weight_kg"]["min"]     = 0;
            parent::$_schema["user_weight"]["weight_lb"]["min"]     = 0;
            parent::$_schema["user_weight"]["fatpercent"]["min"]    = 0;
        }
        
        public function __set($key,$value) {
            parent::__set($key,$value);
            
            switch ($key) {
                case "weight_kg":
                    if (isset($value)) {
                        parent::$_schema["user_weight"]["weight_lb"]["allowNull"] = false;
                    }
                    break;
                
                case "weight_lb":
                    if (isset($value)) {
                        parent::$_schema["user_weight"]["weight_kg"]["allowNull"] = false;    
                    }
                    break;
            }
        }
    }